<template>
  <el-dialog title="新增人员" :visible.sync="dialogVisible" width="550px" class="popup height50" :before-close="handleClose">
    <div class="scrollbar-wrap">
      <el-scrollbar class="scrollbar-x" style="height:100%">
        <el-form ref="formInline" :model="formInline" :rules="rules" label-width="100px">
          <el-form-item label="用户名:" prop="pass">
            <el-input v-model.number="formInline.age" />
          </el-form-item>
          <el-form-item label="姓名:" prop="checkPass">
            <el-input v-model="formInline.checkPass" type="password" autocomplete="off" />
          </el-form-item>
          <el-form-item label="性别:" prop="age">
            <el-input v-model="formInline.sex" />
          </el-form-item>
          <el-form-item label="身份证号:" prop="age">
            <el-input v-model.number="formInline.age" />
          </el-form-item>
          <el-form-item label="人像照片:" prop="age">
            <el-input v-model.number="formInline.avatar" />
          </el-form-item>
          <el-form-item label="手机号:" prop="age">
            <el-input v-model.number="formInline.age" />
          </el-form-item>
          <el-form-item label="角色:" prop="age">
            <el-input v-model="formInline.role" />
          </el-form-item>
          <el-form-item label="部门:" prop="age">
            <el-input v-model.number="formInline.dep" />
          </el-form-item>
          <el-form-item label="岗位:" prop="age">
            <el-input v-model.number="formInline.age" />
          </el-form-item>
          <el-form-item label="邮箱:" prop="age">
            <el-input v-model.number="formInline.email" />
          </el-form-item>
          <el-form-item label="备注:" prop="age">
            <el-input v-model.number="formInline.email" />
          </el-form-item>
        </el-form>
      </el-scrollbar>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" size="small" @click="handleAdd">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import TreeSelect from '@/components/TreeSelect'
import { addPersonnel } from '@/api/personnel'
export default {
  components: {
    TreeSelect
  },
  data() {
    return {
      dialogVisible: false,
      formInline: {
        username: '',
        password: '',
        phone: '',
        role: ['1']
      },
      defaultProps: {
        parent: 'parentId', // 父级唯一标识
        value: 'id', // 唯一标识
        label: 'label', // 标签显示
        children: 'children' // 子级
      },
      isShowSelect: false, // 选择面板，默认隐藏
      officeTreeList: this.$config.treeList, // 树形结构数据
      selectedOfficeIds: '', // 选择后返回的选中id，以逗号拼接
      selectedOffices: [], // 选择后返回的选中对象，
      clearTreeSelect: 0,
      nodeKey: 'id', // 树形结构数据中对应的属性名称，可改为自己数据中属性
      defaultCheckedKeys: [] // 默认初次选中的数据
    }
  },
  computed: {
    rules() {
      return {
        // pass: [
        //   { required: true, message: '请输入活动名称', trigger: 'blur' },
        // ],
        // checkPass: [
        //   { required: true, message: '请输入活动名称', trigger: 'blur' },
        // ],
        // age: [
        //   { required: true, message: '请输入活动名称', trigger: 'blur' },
        // ]
      }
    }

  },
  methods: {
    togglePopup(flag) {
      this.dialogVisible = flag
    },
    handleClose(done) {
      this.togglePopup(false)
    },
    popoverHide(checkedIds, checkedData, el) {
      console.log(checkedIds, checkedData)
      if (el) {
        eval(' ( this.' + el + ' = checkedIds) ')
        console.log(2, this.formInline.eptIdList)
      }
    },
    handleAdd() {
      addPersonnel(this.formInline)
        .then(res => {
          if (res.code === 0) {
            this.$message.success(res.msg || '成功')
            this.togglePopup(false)
            this.$emit('refresh')
          }
        })
        .catch(err => {
          this.togglePopup(false)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~styles/popup.scss';
</style>
